$(function () {
	
	var init = function () {
		$("input[name='file-text']").click(function () {
			$("input[type='file']").click();
		});
		
		$("input[type='file']").change(function () {
			var val = $(this).val();
			
			if (val !== "") {
				$("input[name='file-text']").val(val);
			}
		});
	};
	
	var methods = {
		importScore: function () {
			
			var val = $("input[name='file-text']").val();
			if ('' == val) {
				bootbox.alert({
				    message: '请先选择文件',
				    size: 'small'
				});
				return;
			}
			
			$.showloading();
        	var formData = new FormData();
        	formData.append('file', $('input[name="file"]').get(0).files[0]);
        	this.$http.post(
				"score/import",
				formData
			).then((res) => {
				var data = res.data; 
				console.log(data);
				
				bootbox.alert({
				    message: data.msg,
				    size: 'small'
				});
			}, (res) => {
				bootbox.alert({
				    message: "系统错误",
				    size: 'small'
				});
			}).finally(function() {
				$.hideloading();
				$('input[name="file-text"]').val('');
				$('input[name="file"]').val('');
			});
		}
	};
	
	var app = new Vue({
		el: '#app',
		data: {
			
		},
		mounted: init,
        methods: methods
	});
});